package com.app.dao.mysql;


import com.app.domain.YjData;
import com.app.domain.YjUploadData;
import com.app.domain.jwjb.YjDataTime;
import org.apache.ibatis.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

@Mapper
public interface YjDataMapper {
    /**
     * 新增
     *
     * @param yjData
     */
/*    @Insert("insert into yjdata(device_code,bridge_code,duct_code,mudjack_date,begin_time,end_time,mudjack_pressure,slurry_pressure,stabilize_pressure,pressurize_time,water_binder_ratio,theory_volume,practical_volume,practical_mudjack_value,practical_water_value,environment_temperature,slurry_temperature,practical_fluidity,remark,mudjack_curve_graph,state) values(#{device_code},#{bridge_code},#{duct_code},#{mudjack_date},#{begin_time},#{end_time},#{mudjack_pressure},#{slurry_pressure},#{stabilize_pressure},#{pressurize_time},#{water_binder_ratio},#{theory_volume},#{practical_volume},#{practical_mudjack_value},#{practical_water_value},#{environment_temperature},#{slurry_temperature},#{practical_fluidity},#{remark},#{mudjack_curve_graph},#{state})")
    @Options(useGeneratedKeys = true, keyProperty = "id",keyColumn = "id")*/
    int save(YjData yjData);

    int save1(YjUploadData yjUploadData);

    /**
     * 查询所有
     *
     * @return
     */
    @Select("select * from yjdata")
    List<YjData> findAll();

    /**
     * 根据设备号,梁号,孔道号查询
     *
     * @param yjData
     * @return
     */
    @Select("select * from yjdata where device_code=#{device_code} and bridge_code=#{bridge_code} and duct_code=#{duct_code}")
    YjData findByDeviceCode(YjData yjData);

    /**
     * 根据设备号,梁号,孔道号更新
     */
    @Update("update yjdata set mudjack_date=#{mudjack_date},begin_time=#{begin_time},end_time=#{end_time},mudjack_pressure=#{mudjack_pressure},slurry_pressure=#{slurry_pressure},stabilize_pressure=#{stabilize_pressure},pressurize_time=#{pressurize_time},water_binder_ratio=#{water_binder_ratio},theory_volume=#{theory_volume},practical_volume=#{practical_volume},practical_mudjack_value=#{practical_mudjack_value},practical_water_value=#{practical_water_value},environment_temperature=#{environment_temperature},slurry_temperature=#{slurry_temperature},practical_fluidity=#{practical_fluidity},remark=#{remark},mudjack_curve_graph=#{mudjack_curve_graph},state=#{state} where id = #{id}")
    void updateByDeviceCode(YjData yjData);

    List<YjData> selectList(@Param("bridgeCode") String bridgeCode, @Param("device_code") String device_code, @Param("state") String state);

    @Select("select * from yjdata where id=#{id}")
    YjData findOne(String id);

    @Update("update yjdata set state=#{state} where id =#{id}")
    void updateById(@Param("state") String state, @Param("id") String id);
    @Update("update yjdata set state=#{state} where id =#{id}")
    int updateStateById(@Param("state") String state, @Param("id") String id);
    @SelectProvider(type = SqlProvider.class, method = "updateYjDataByField")
    void ConditionUpdate(@Param("id") String id, @Param("field") String field, @Param("value") String value);

    /**
     * 查询压浆流量表
     *
     * @return
     */
    @Select("SELECT GROUP_CONCAT(mudjack_curve_graph)  FROM yjdata WHERE device_code=#{device_code} AND bridge_code=#{bridge_code} ORDER BY duct_code")
    String selectMcg(@Param("device_code") String device_code, @Param("bridge_code") String bridge_code);

    /**
     * 查询单个孔道流量表
     *
     * @param device_code
     * @param bridge_code
     * @param duct_code
     * @return
     */
    @Select("SELECT mudjack_curve_graph  FROM yjdata WHERE device_code=#{device_code} AND bridge_code=#{bridge_code} and duct_code=#{duct_code}")
    String selectOneMcg(@Param("device_code") String device_code, @Param("bridge_code") String bridge_code, @Param("duct_code") String duct_code);

    /**
     * 实测浆料体积和
     *
     * @return
     */
    @Select("SELECT CONVERT(SUM(practical_mudjack_value),DECIMAL(10,2)) FROM yjdata WHERE device_code=#{device_code} AND bridge_code=#{bridge_code}")
    Float sumPmv(@Param("device_code") String device_code, @Param("bridge_code") String bridge_code);

    /**
     * 查询单个孔道浆料体积
     *
     * @param device_code
     * @param bridge_code
     * @return
     */
    @Select("SELECT practical_mudjack_value FROM yjdata WHERE device_code=#{device_code} AND bridge_code=#{bridge_code} and duct_code=#{duct_code}")
    Float onePmv(@Param("device_code") String device_code, @Param("bridge_code") String bridge_code, @Param("duct_code") String duct_code);

    @Select("SELECT duct_code, CONCAT(mudjack_date,' ',begin_time) startTime ,CONCAT(mudjack_date,' ',end_time) endTime FROM yjdata WHERE device_code=#{device_code} AND bridge_code =#{bridge_code}")
    List<YjDataTime> findStartAndEndTime(@Param("device_code") String device_code, @Param("bridge_code") String bridge_code);

    @Select("SELECT  * FROM yjdata t1,(SELECT device_code,bridge_code FROM yjdata WHERE id = #{id}) t2 WHERE t1.device_code = t2.device_code AND t1.bridge_code = t2.bridge_code")
    List<YjData> findYjDataListById(String id);

    @Select("select mudjack_curve_graph from yjdata where id =#{id}")
    String findMcgById(String id);

    @Select("select begin_time from yjdata where id =#{id}")
    String findBeginTimeById(String id);

    @Select("SELECT duct_code, CONCAT(mudjack_date,' ',begin_time) startTime ,CONCAT(mudjack_date,' ',end_time) endTime FROM yjdata WHERE id=#{id}")
    YjDataTime findStartAndEndTimeById(String id);

    @Select("SELECT * FROM yjdata WHERE device_code=#{device_code} AND bridge_code=#{bridge_code} LIMIT 1")
    YjData findOneByDeviceCode(@Param("device_code") String device_code, @Param("bridge_code") String bridge_code);

    @Select("SELECT * FROM yjdata WHERE device_code=#{device_code} AND bridge_code=#{bridge_code}")
    List<YjData> findYjdataByDeviceCodAndBridgeCode(@Param("device_code") String device_code, @Param("bridge_code") String bridge_code);

    @Select("SELECT * FROM yjdata WHERE device_code=#{device_code}")
    List<YjData> findByDeviceCode1(@Param("device_code") String device_code);

    @Select("select MAX(end_time) from yjdata WHERE device_code=#{device_code} and mudjack_date=#{mudjack_date}")
    String findMaxEndTime(@Param("device_code") String device_code, @Param("mudjack_date") String mudjack_date);

    List<YjData> findList(String[] ids);

    Map<String,Object> findDate(List<Integer> ids);

    List<YjData> selectDeviceCodesList(@Param("bridgeCode")String bridgeCode,@Param("deviceCodes") String[] deviceCodes,@Param("state") String state);
    /**
     * 根据条件选择泥浆日期列表
     * 该方法用于查询特定桥梁代码、设备代码、泥浆日期和状态下的一组泥浆数据
     * 主要用于数据筛选和查询操作
     *
     * @param bridgeCode 桥梁代码，用于标识特定的桥梁
     * @param deviceCode 设备代码，用于标识特定的设备
     * @param mudjackDate 泥浆日期，格式为YYYY-MM-DD，用于筛选特定日期的数据
     * @param state 状态，用于筛选特定状态下的数据
     * @return 返回一个YjData对象列表，包含符合筛选条件的泥浆数据记录
     */
    List<YjData> selectMudjackDateList(@Param("bridgeCode")String bridgeCode,@Param("device_code")  String deviceCode, @Param("mudjackDate") String mudjackDate,@Param("state") String state);

}
